home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Utilitaires divers / Images / Image 1.37 ƒ / Macros / Corpus Collosum Macros < prev    next >
Encoding:
Text File  |  1991-03-28  |  4.1 KB  |  200 lines  |  [TEXT/MSWD]

  1. {
  2. This is a set of macros for measuring the area of various regions in the corpus collosum in MRI scans. It assumes that the scans are 256x256, that you are using a 19" monitor, that the Clipboard buffer is set to 600K, and that you have a lot of RAM.
  3.  
  4. This is the procedure:
  5.  
  6. 1) Open or activate the scan to be analyzed and type Z.
  7. 2) Draw a base line using the ruler.
  8. 3) Draw perpendicular lines by typing S or R.
  9. 4) Draw a perpendicular line at an arbitrary location by clicking
  10.    on the base line with the ruler and typing A.
  11. 5) Outline the corpus collosum.
  12. 6) Threshold by typing B.
  13. 7) Measure the areas by clicking inside each region with the wand.
  14. 8) Revert to grayscale by typing G. (Optional)
  15. 9) Dispose of the 768x768 working window by typing D.
  16. }
  17.  
  18. var  {Global variables}
  19.   WindowNum:integer;
  20.   x1,y1,x2,y2,LineWidth:integer;
  21.   size,angle,dx,dy,pi,theta:real;
  22.   width,height,dx,dy,i:integer;
  23.  
  24.  
  25. macro 'Zoom Window [Z]';
  26. var
  27.   top,left,width,height:integer;
  28. begin
  29.   GetPicSize(width,height);
  30.   if width>600 then begin
  31.     PutMessage('Window has already been zoomed.');
  32.     exit;
  33.   end;
  34.   KillRoi;
  35.   WindowNum:=PicNumber;
  36.   SetScaling('Nearest; New Window');
  37.   ScaleAndRotate(3,3,0);
  38.   ChangeValues(254,255,253); {Reserve 254-255(black) for graphics}
  39.   SetForegroundColor(254);
  40.   ApplyLUT;
  41.   SetLineWidth(1);
  42. end;
  43.  
  44.  
  45. procedure DrawPerpendicularLine(x,y:integer);
  46. begin
  47.   moveto(x,height-y);
  48.   lineto(x+size*cos(theta+angle),height-(y+size*sin(theta+angle)));
  49.   moveto(x,height-y);
  50.   lineto(x+size*cos(theta-angle),height-(y+size*sin(theta-angle)));
  51. end;
  52.  
  53.  
  54. procedure DrawLines(nSegments:integer);
  55. begin
  56.   for i:=1 to nSegments-1 do
  57.     DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  58. end;
  59.  
  60.  
  61. procedure DrawLeftLine;
  62. var
  63.   nSegments,i:integer;
  64. begin
  65.   nSegments:=5;
  66.   i:=1;
  67.   DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  68. end;
  69.  
  70.  
  71. procedure DrawRightLine;
  72. var
  73.   nSegments,i:integer;
  74. begin
  75.   nSegments:=5;
  76.   i:=4;
  77.   DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  78. end;
  79.  
  80.  
  81. procedure DrawThePerpendiculars;
  82. begin
  83.   KillRoi;
  84.   GetLine(x1,y1,x2,y2,LineWidth);
  85.   if (x1<0) or ((x2-x1)<10) then begin
  86.     PutMessage('Use the ruler to draw a base line first.');
  87.     exit;
  88.   end;
  89.   size:=sqrt(sqr(x2-x1)+sqr(y2-y1))/2;
  90.   angle:=90; {degrees}
  91.   pi:=3.14159;
  92.   GetPicSize(width,height);
  93.   y1:=height-y1;
  94.   y2:=height-y2;
  95.   angle:=(angle/180)*pi;
  96.   dx:=x1-x2;
  97.   dy:=y1-y2;
  98.   if dx=0 then begin
  99.     if dy>=0 then theta:=pi/2 else theta:=3/2*pi
  100.   end else begin
  101.     theta:=arctan(dy/dx);
  102.     if dx<0 then theta:=theta+pi;
  103.   end;
  104.   dx:=x2-x1;
  105.   dy:=y2-y1;
  106.   SetForegroundColor(255);
  107.   DrawLines(2);
  108.   DrawLines(3);
  109. end;
  110.  
  111.  
  112. Macro 'Draw Perpendicular Lines-Left[S]';
  113. begin
  114.   DrawThePerpendiculars;
  115.   DrawLeftLine;
  116. end;
  117.  
  118.  
  119. Macro 'Draw Perpendicular Lines-Right[R]';
  120. begin
  121.   DrawThePerpendiculars;
  122.   DrawRightLine;
  123. end;
  124.  
  125.  
  126. macro 'Draw Arbitrary Perpendicular Line [A]';
  127. var
  128.   xx1,yy1,xx2,yy2:integer;
  129.   fraction:real;
  130. begin
  131.   if angle=0 then begin
  132.     PutMessage('Draw the other perpendiclular lines first.');
  133.     exit;
  134.   end;
  135.   if dx=0 then begin
  136.     PutMessage('Draw base line first.');
  137.     exit;
  138.   end;
  139.   GetLine(xx1,yy1,xx2,yy2,LineWidth);
  140.   if not ((xx1>x1) and (xx1<x2)) then begin
  141.     PutMessage('Click with ruler first.');
  142.     exit;
  143.   end;
  144.   fraction:=(xx1-x1)/dx;
  145.   DrawPerpendicularLine(x1+round(dx*fraction),y1+round(dy*fraction));
  146. end;
  147.  
  148.  
  149. macro 'Make Binary [B]';
  150. var
  151.   top,left,width,height:integer;
  152. begin
  153.   GetRoi(top,left,width,height);
  154.   if width=0 then begin
  155.     PutMessage('Please outline first.');
  156.     exit;
  157.   end;
  158.   DrawBoundary;
  159.   KillRoi;
  160.   SetThreshold(255);
  161.   MeasureArea(true);
  162.   MeasureDensity(false);
  163.   LabelParticles(false);
  164.   IncludeInteriorHoles(true);
  165.   WandAutoMeasure(true);
  166.   ResetCounter;
  167.   ShowResults;
  168. end;
  169.  
  170. macro 'Make Grayscale [G]';
  171. begin
  172.   ResetGrayMap;
  173.   KillRoi;
  174. end;
  175.  
  176. macro 'Dispose of Window [D]';
  177. var
  178.   width,height:integer;
  179. begin
  180.   GetPicSize(width,height);
  181.   if width>600
  182.     then dispose
  183.     else exit;
  184.   if windowNum<>0 then SelectPic(WindowNum);
  185. end;
  186.  
  187. macro 'Adjust Areas [Q]';
  188. var
  189.   i:integer;
  190. begin
  191.   for i:=1 to rCount do
  192.     rArea[i]:=rArea[i]/9;
  193.   ShowResults;
  194. end;
  195.  
  196.  
  197.  
  198.  
  199.  
  200.